package com.bolt.report.engine.calculator;

import com.bolt.report.engine.BindData;
import com.bolt.report.engine.Calculator;
import com.bolt.report.engine.fill.FillContext;
import com.bolt.report.engine.fill.FillReturnValue;
import com.bolt.report.engine.model.Cell;
import com.bolt.report.engine.model.Expression.CalculatorExpression;

public class CountCalculator implements Calculator {
    @Override
    public Object evaluate(FillContext context, BindData data, CalculatorExpression expr, Cell cell) {
        int count = 0;
        FillReturnValue values = context.getReturnValue(data.getKey());
        int start = data.start(), end = data.end();
        while (values.next(start, end)) {
            count++;
        }
        return count;
    }
}